
// ChatConferencesServerDlg.h : header file
//
#define PORT 27000
#define WM_SOCKET WM_USER+1
#include <vector>
#include "Data.h"
using namespace std;
#pragma once


// CChatConferencesServerDlg dialog
class CChatConferencesServerDlg : public CDialog
{
// Construction
public:
	CChatConferencesServerDlg(CWnd* pParent = NULL);	// standard constructor

// Dialog Data
	enum { IDD = IDD_CHATCONFERENCESSERVER_DIALOG };

protected:
	virtual void DoDataExchange(CDataExchange* pDX);	// DDX/DDV support
//****************************************************<<
	// variable
	int sendType;
	CString sReceivedMessage;
	int buffLength;
	CString sTotalMessage;
	
	vector <USER> arrUsersJustConnect;
	vector <USER> arrUsersOnline;

	//int iNumUser, iTotalUser;;
	SOCKET sockServer,sockClient;
	struct sockaddr_in serverAdd;
	CListBox *pListMessages, *pListUsers;
	
		//private chat
	bool isPrivate;
	vector <USER> arrUserPrivateOnline;
	//vector <CString> arrDstUserPrivate;
	
	// method
	//void initArraySocket(int n);
	virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam);
	void SockMsg(WPARAM wParam, LPARAM lParam);
	int findSocketClient(WPARAM wparam);
	void choseAction(vector<CString> arrReceivePackage, WPARAM wParam);
	void chatRoom(PACKAGE pack, WPARAM wParam);
	void chatPrivate(PACKAGE pack, WPARAM wParam);
	int createPrivatePackage(int code, CString sUsername);
	int createRoomPackage(int code, CString message, CString ownerOfMessage);
	int sendConferencePackage(CString package, CString ownerOfMessage);
	int sendEndToEnd(CString package, SOCKET sClient);
	CString listUsersOnline();
	PACKAGE parseMessage(vector<CString> arrMessage);
	bool exitstedUser(CString sUsername);
	int findUser(CString sUsername);
	int findUserInList(CString sUsername);
	void AddString(CString message);

//****************************************************>>

// Implementation
protected:
	HICON m_hIcon;

	// Generated message map functions
	virtual BOOL OnInitDialog();
	afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
	afx_msg void OnPaint();
	afx_msg HCURSOR OnQueryDragIcon();
	DECLARE_MESSAGE_MAP()
public:
	afx_msg void OnBnClickedBtnListen();
	afx_msg void OnClose();
	int findSocketPrivateClient(WPARAM wParam);
	int findSocketUserJustConnect(WPARAM wParam);
	// return index of private user
	int findPrivateUser(CString strUsername, CString dstUsername);
};
